#include <cstdio>

typedef unsigned int uint;


inline void triangle_wave (uint amplitude)
{
	static const char *w[] = {
		"1",
		"22",
		"333",
		"4444",
		"55555",
		"666666",
		"7777777",
		"88888888",
		"999999999"
	};

	uint i;

	for (i = 0; i < amplitude; ++i)
		puts(w[i]);
	--i;
	while (i--)
		puts(w[i]);
}


int main ()
{
	uint test_cases, amplitude, frecuency;

	scanf ("%d", &test_cases);
	while (test_cases--)
	{
		scanf ("%d %d", &amplitude, &frecuency);
		while (frecuency--)
		{
			triangle_wave (amplitude);
			if (test_cases || frecuency)
				putchar ('\n');
		}
	}

	return 0;
}